package com.m.springblog.model;

import com.m.springblog.common.Constants;
import lombok.Data;

@Data
public class Result<T> {
    private Integer code;//200成功 -1失败
    private String errorMsg;
    private T data;

    public static <T> Result<T> success(T data){
        Result<T> result = new Result<T>();
        result.setCode(Constants.RESULT_SUCCESS);
        result.setErrorMsg("");
        result.setData(data);

        return result;
    }
    public static <T> Result<T> fail(String errorMsg){
        Result<T> result = new Result<T>();
        result.setCode(Constants.RESULT_FAIL);
        result.setErrorMsg(errorMsg);
        return result;
    }
    public static <T> Result<T> fail(String errorMsg, T data){
        Result<T> result = new Result<T>();
        result.setCode(Constants.RESULT_FAIL);
        result.setErrorMsg(errorMsg);
        result.setData(data);
        return result;
    }
}
